#include <avr/io.h>
#include <stdlib.h>
#include "lcd.h"
#include "keypad.h"
#include "password.h"

void avr_init(void)
{
    lcd_init(LCD_DISP_ON);
    password_init();
}

int main(void)
{
    int8_t var01=0;
    char var02[3]= {0};

    avr_init();
    lcd_gotoxy(0,0);
    lcd_puts("uji coba lib");
    lcd_gotoxy(0,1);
    lcd_puts("4x4keypad");
    _delay_ms(1000);
    while(1)
    {
        lcd_clrscr();
        lcd_puts("tekan keypad");
        lcd_gotoxy(0,1);
        lcd_puts("16==lanjut");
        _delay_ms(2000);

        do
        {
            do
            {
                var01=keypad_read();
            }
            while(var01==0x10);
            itoa(var01&0x0f,var02,10);
            lcd_gotoxy(0,0);
            lcd_puts(var02);
            _delay_ms(500);
        }
        while(var01!=16);

        lcd_clrscr();
        lcd_puts("Enter pass");
        _delay_ms(1000);

        lcd_clrscr();
        password_masuk();

        lcd_clrscr();
        lcd_puts("save pass");
        _delay_ms(1000);

        lcd_clrscr();
        password_save();

        lcd_puts("check password");
        _delay_ms(1000);

        lcd_clrscr();
        password_masuk();

        lcd_clrscr();
        if(password_check()==0)
        {
            lcd_puts("correct");
        }
        else
        {
            lcd_puts("wrong");
        }
        _delay_ms(5000);
    }
    return 0;
}
